
/**
 * @fileoverview Simple implementation of javax.servlet.ServletRequest.
 * @see http://docs.oracle.com/javaee/5/api/javax/servlet/ServletRequest.html
 * @see http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml
 * @see https://developers.google.com/closure/compiler/docs/js-for-compiler
 */



/**
 * Simple implementation of javax.servlet.ServletRequest.
 * @constructor
 * @see http://docs.oracle.com/javaee/5/api/javax/servlet/ServletRequest.html
 */
net.ServletRequest = function() {

  /**
   * Returns the value of a request parameter as a string, or empty string if
   * the parameter does not exist.
   * @param {string} name A <code>string</code> specifying the name of the
   *     parameter.
   * @return {string} Returns a <code>string</code> representing the single
   *     value of the parameter.
   * @this {net.ServletRequest}
   */
  this.getParameter = function(name) {
    /** @type {!Object.<string, string>} */ var map = this.getParameterMap();
    return map[/** @type {string} */ (name)] || '';
  };

  /**
   * Returns a map of the parameters of this request including parameters from
   * parsed from query string and hash.
   * @return {!Object.<string, string>} Map containing parameter names as keys
   *     and parameter values as map values.
   */
  this.getParameterMap = function() {
    /** @type {!Object.<string, string>} */ var map = {};
    /** @type {!Array.<string>} */
    var pairs = location.search.substr(1).split('&').concat(
        location.hash.substr(1).split('&'));
    for (/** @type {number} */ var i = 0; i < pairs.length;) {
      /** @type {!Array.<string>} */ var pair = pairs[i++].split('=');
      /** @type {string} */ var key = pair[0];
      if (key) map[key] = (decodeURIComponent || unescape)(pair[1]);
    }
    return map;
  };
};
